from selenium.webdriver.common.by import By

from Base.base_page import AppBasePage


class ListenPage(AppBasePage):
    """
    点击收听模式按钮
    点击声音暂停按钮
    点击播放列表
    下滑查看
    driver.swipe(start_x, start_y, end_x, end_y, duration=None)
    退出
    点击声音开始按钮
    点击下一首
    退出
    点击声音暂停按钮
    退出
    关闭收听模式
    """
    def __init__(self):
        super().__init__()
        # 点击收听模式按钮
        self.listen_button = (By.XPATH,'//*[@resource-id="com.ss.android.article.news:id/a5r"]')
        # 点击声音暂停按钮
        self.listen_pause = (By.XPATH,'(//android.widget.RelativeLayout)[5]')
        # 点击播放列表
        self.listen_playlist = (By.XPATH,'(//android.widget.RelativeLayout)[4]')
        # 下滑查看
        # driver.swipe(start_x, start_y, end_x, end_y, duration=None)
        # 退出
        self.listen_exit = (By.XPATH,'//android.widget.ImageView')
        # 点击声音开始按钮
        self.listen_start = (By.XPATH,'(//android.widget.RelativeLayout)[5]')
        # 点击下一首
        self.listen_next = (By.XPATH,'(//android.widget.RelativeLayout)[6]')
        # 退出
        self.interface_exit = (By.XPATH,'//*[@resource-id="com.ss.android.article.news:id/a7q"]')
        # 点击声音暂停按钮
        self.floating_pause = (By.XPATH,'//*[@content-desc="暂停"]')
        # 退出
        self.floating_exit = (By.XPATH,'//*[@content-desc="关闭"]')
        # 关闭收听模式
        self.close_listen = (By.XPATH,'//*[@resource-id="com.ss.android.article.news:id/a5r"]')

    def to_listen_mode01(self):
        self.click_element(self.find_element(self.listen_button))
        self.click_element(self.find_element(self.listen_pause))
        self.click_element(self.find_element(self.listen_playlist))
    def to_listen_mode02(self):
        self.click_element(self.find_element(self.listen_exit))
        self.click_element(self.find_element(self.listen_start))
        self.click_element(self.find_element(self.listen_next))
        self.click_element(self.find_element(self.interface_exit))
        self.click_element(self.find_element(self.floating_pause))
        self.click_element(self.find_element(self.floating_exit))
        self.click_element(self.find_element(self.close_listen))


